package com.dcms.admin.service.impl;

import com.dcms.admin.bean.Template;
import com.dcms.admin.dao.TemplateMapper;
import com.dcms.admin.service.ITemplateService;
import com.dcms.util.ResultBean;
import com.dcms.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Created by 90844 on 2018/2/25.
 */
@Service
public class TemplateServiceImpl implements ITemplateService {

    @Autowired
    private TemplateMapper templateMapper;


    @Transactional
    public ResultBean addTemplate(Template template) throws Exception {
       int rs = templateMapper.insertTemplate(template);
       if (rs<1){
           return new ResultBean(10098,"操作失败");
       }
        return new ResultBean();
    }

    public ResultBean showTemplates(Map map) throws Exception{
        List<Map> rs = templateMapper.selectTemplates(map);
        if (null==rs || 0==rs.size()){
            return new ResultBean(10096,"未查询到结果");
        }
        return new ResultBean(rs);
    }

    @Transactional
    public ResultBean removeTemplate(Map map) throws Exception{

        if (null==map.get("template_user_id")&&null==map.get("template_id")){
            return new ResultBean(10095,"参数缺失");
        }
        int rs = templateMapper.deleteTemplate(map);
        if (rs<1){
            return new ResultBean(10098,"操作失败");
        }
        return new ResultBean();
    }
}
